function getQueryString(name) {
    var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return result[1];
}

function goPage(page) {
    // alert('go3')
    goPage(page, null)
}

function goPage(page, keys) {
    var currentPage = getQueryString('page')
    var url = window.location.pathname + window.location.search
    if (window.location.search == '') {
        url = url + '?page=' + page;
    } else {
        if (url.indexOf("page=") != -1) {
            url = url.replace("page=" + currentPage, "page=" + page)
        } else {
            url = url + "&page=" + page
        }
    }
    if (keys != null) {
        for (var i = 0; i < keys.length; i++) {
            // console.log(i, array[i])
            var item = keys[i];
            var key = item.key;
            var value = getQueryString(key)
            if (url.indexOf(key + "=") == -1) {
                url = url + "&" + key + '=' + item.value
            } else {
                url = url.replace(key + "=" + value, key + "=" + item.value)
            }
        }
    }
    this.window.location = url
}

function goDownload() {
    var keys = [
        { key: 'dl', value: 1 }
    ]
    var currentPage = getQueryString('page')
    var page = currentPage
    var url = window.location.pathname + window.location.search
    if (window.location.search == '') {
        url = url + '?page=' + page;
    } else {
        if (url.indexOf("page=") != -1) {
            url = url.replace("page=" + currentPage, "page=" + page)
        } else {
            url = url + "&page=" + page
        }
    }
    if (keys != null) {
        for (var i = 0; i < keys.length; i++) {
            // console.log(i, array[i])
            var item = keys[i];
            var key = item.key;
            var value = getQueryString(key)
            if (url.indexOf(key + "=") == -1) {
                url = url + "&" + key + '=' + item.value
            } else {
                url = url.replace(key + "=" + value, key + "=" + item.value)
            }
        }
    }
    this.window.open(url)
}

function goPageSize(pageSize) {
    var currentPageSize = getQueryString('pageSize')
    var url = window.location.pathname + window.location.search
    if (window.location.search == '') {
        url = url + '?pageSize=' + pageSize;
    } else {
        if (url.indexOf("pageSize=") != -1) {
            url = url.replace("pageSize=" + currentPageSize, "pageSize=" + pageSize)
        } else {
            url = url + "&pageSize=" + pageSize
        }
    }
    this.window.location = url
}

function goPages(page) {
    var currentPage = getQueryString('page')
    var url = window.location.pathname + window.location.search
    if (window.location.search == '') {
        url = url + '?page=' + page;
    } else {
        if (url.indexOf("page=") != -1) {
            url = url.replace("page=" + currentPage, "page=" + page)
        } else {
            url = url + "&page=" + page
        }
    }
    this.window.location = url
}